package Offer019;

/**
 * 最多删除一个元素 使得字符串成为回文字符串
 * @author 23737
 * @time 2021.12.9
 */
public class Test {
    public static void main(String[] args) {

    }
}

class Solution {
    public boolean validPalindrome(String s) {
        int n = s.length();
        if(n == 0){
            return false;
        }
        int start = 0;
        int end = n-1;
        while(start < end){
            if(s.charAt(start) != s.charAt(end)){
                return (validPalindrome(s,start+1,end) || validPalindrome(s,start,end-1));
            }
            start++;
            end--;
        }
        return true;
    }
    public boolean validPalindrome(String s,int start,int end){
        while(start < end){
            if(s.charAt(start) != s.charAt(end)){
                return false;
            }
            start++;
            end--;
        }
        return true;
    }
}
